package com.itheima.chapter10.atom2;

import java.util.concurrent.atomic.AtomicInteger;

public class demo1 {
    public static void main(String[] args) {
        AtomicInteger ac1 =new AtomicInteger(10);
        AtomicInteger ac2 =new AtomicInteger();
        System.out.println(ac1);
        System.out.println(ac2);
        System.out.println(ac1.get());
        System.out.println(ac2.get());
        System.out.println("----------------");
        //当前值加1，返回自增前值
        int andIncrement = ac1.getAndIncrement();
        System.out.println(andIncrement);
        System.out.println(ac1.get());
        System.out.println("----------------");
        //当前值加1，返回自增后值
        int i = ac1.incrementAndGet();
        System.out.println(i);
        System.out.println(ac1.get());
        System.out.println("----------------");
        int addAndGet = ac1.addAndGet(20);
        System.out.println(addAndGet);
        System.out.println(ac1.get());
        System.out.println("----------------");
        int andSet = ac1.getAndSet(20);
        System.out.println(andSet);
        System.out.println(ac1.get());
        System.out.println("----------------");


    }
}
